package Eyjafjalla.action;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.vfx.combat.FlashAtkImgEffect;

public class SilentAction extends AbstractGameAction {
    public SilentAction(AbstractCreature target, DamageInfo info,int type){
        this.info = info;
        this.setValues(target, info);
        this.actionType = ActionType.DAMAGE;
        this.startDuration = Settings.ACTION_DUR_XFAST;
        this.duration = this.startDuration;
        this.type = type;
    }

    @Override
    public void update() {
        if(type!=2&&type!=3&&this.shouldCancelAction()){
            this.isDone = true;
        }
        else {
            this.tickDuration();
            if(this.isDone){
                if(type==1||type==3){
                    totalDamage = 0;
                }
                AbstractDungeon.effectList.add(new FlashAtkImgEffect(this.target.hb.cX, this.target.hb.cY, AttackEffect.SLASH_DIAGONAL, false));
                this.target.damage(this.info);
                if(this.target.lastDamageTaken>0){
                    totalDamage+=target.lastDamageTaken;
                }
                if((type==2||type==3)&&totalDamage>=4){
                    addToTop(new GainBlockAction(this.source,totalDamage/4));
                }

                if (AbstractDungeon.getCurrRoom().monsters.areMonstersBasicallyDead()) {
                    AbstractDungeon.actionManager.clearPostCombatActions();
                }
            }
        }
    }

    private static int totalDamage = 0;
    private DamageInfo info;
    int type;
}
